package com.mz.ozy.mvp.presenter;


import android.app.Activity;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.ExchangeOrderBean;
import com.mz.ozy.bean.GoodsSpecBean;
import com.mz.ozy.bean.ShopDetailBean;
import com.mz.ozy.bean.ShopSpecListBean;
import com.mz.ozy.mvp.model.PrivateDetailModel;
import com.mz.ozy.mvp.model.ShopDetailModel;
import com.mz.ozy.mvp.view.PrivateDetailContract;
import com.mz.ozy.mvp.view.ShopDetailContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;


/**
 * @author
 * @date 2018/7/25
 * @description
 */

public class PrivateDetailPresenter extends BasePresenterImpl<PrivateDetailContract.View> implements PrivateDetailContract.Presenter {
    private PrivateDetailModel mShopDetailModel;

    public PrivateDetailPresenter() {
        mShopDetailModel = new PrivateDetailModel();
    }

    @Override
    public void obtainShopDetailInfo(Activity activity, String goodsId) {
        mShopDetailModel.obtainShopDetailInfo(activity, goodsId)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<ShopDetailBean>(mView) {
                    @Override
                    public void onSuccesss(ShopDetailBean shopDetailBean) {
                        mView.obtainShopDetailInfoSuccess(shopDetailBean);
                    }
                });
    }

    @Override
    public void obtainSpecList(Activity activity, String goodsId) {
        mShopDetailModel.obtainSpecList(activity, goodsId)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<ShopSpecListBean>(mView) {
                    @Override
                    public void onSuccesss(ShopSpecListBean listBean) {
                        mView.obtainSpecListSuccess(listBean);
                    }
                });

    }

    @Override
    public void onJoinCar(Activity activity, String goodsID, String ggId, String buyNumber) {

        mShopDetailModel.onJoinCar(activity, goodsID, ggId, buyNumber)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.onJoinCarSuccess(jsonObject);
                    }
                });


    }

    @Override
    public void onGoodsFollow(Activity activity, String gid) {
        mShopDetailModel.onGoodsFollow(activity, gid)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.onGoodsFollowSuccess(jsonObject);
                    }
                });
    }

    @Override
    public void onBuy(Activity activity, String goodsId, String gid) {
        mShopDetailModel.onBuy(activity, goodsId, gid)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<ExchangeOrderBean>(mView) {
                    @Override
                    public void onSuccesss(ExchangeOrderBean jsonObject) {
                        mView.onBuySuccess(jsonObject);
                    }
                });

    }
}
